﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FineUIPro.EmptyProjectNet40
{
    /// <summary>
    /// search 的摘要说明
    /// </summary>
    public class search : IHttpHandler
    {
        //private booksEntities1 db = new booksEntities1();
        FE.BLL.users userbll = new FE.BLL.users();
        FE.BLL.departments dptbll = new FE.BLL.departments();
        // private addressbookEntities db = new addressbookEntities();
        //public void ProcessRequest(HttpContext context)
        //{
        //    context.Response.ContentType = "text/plain";
        //    context.Response.Write("Hello World");
        //}
        public void ProcessRequest(HttpContext context)
        {
            //System.Threading.Thread.Sleep(2000);

            String term = context.Request.QueryString["term"];
            if (!String.IsNullOrEmpty(term))
            {
                term = term.ToLower();

                //var list = db.users.Where(p => p.Name.EndsWith(term)).ToList();

                var list = userbll.GetModelList(" Name like '%"+ term + "%' ");//db.users.Where(p => p.Name.Trim().Contains(term)).ToList();

                JArray ja = new JArray();
                //foreach (string lang in LANGUAGES)
                //{
                //    if (lang.ToLower().Contains(term))
                //    {
                //        ja.Add(lang);
                //    }
                //}
                foreach ( FE.Model.users user in list)
                {
                   
                        ja.Add(user.Name);
                  
                }


                context.Response.ContentType = "text/plain";
                context.Response.Write(ja.ToString());
            }

        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}